package 数字分组求偶数和.main;

public class Main {
    public static int solution(int[] numbers) {
        // Please write your code here
        // 将每个整数转换成字符串形式的数组
        String[] strNumbers = new String[numbers.length];
        for (int i = 0; i < numbers.length; i++) {
            strNumbers[i] = String.valueOf(numbers[i]);
        }
        return dfs(0, 0, strNumbers);
    }

    private static int dfs(int index, int currentSum, String[] numbers) {
        if (index == numbers.length) {
            // 当遍历到最后一个数字组时，检查当前和是否为偶数
            return currentSum % 2 == 0 ? 1 : 0;
        }

        int count = 0;
        for (char digit : numbers[index].toCharArray()) {
            // 对于当前数字组中的每一个数字，进行递归调用
            count += dfs(index + 1, currentSum + Character.getNumericValue(digit), numbers);
        }

        return count;
    }

    public static void main(String[] args) {
        // You can add more test cases here
        System.out.println(solution(new int[] { 123, 456, 789 }) == 14);
        System.out.println(solution(new int[] { 123456789 }) == 4);
        System.out.println(solution(new int[] { 14329, 7568 }) == 10);
    }
}